package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ApArticleDto;
import com.heima.model.article.dtos.ApArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.CollectionBehaviorDto;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.utils.common.UserThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/3/14 9:47
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/v1")
public class ApArticleController{

    @Autowired
    private ApArticleService articleService;

    @PostMapping("article/load")
    public ResponseResult load(@RequestBody ApArticleHomeDto homeDto){
        return articleService.load(homeDto, ArticleConstants.LOAD_MORE);
    }

    @PostMapping("article/loadmore")
    public ResponseResult loadMore(@RequestBody ApArticleHomeDto homeDto){
        return articleService.load(homeDto,ArticleConstants.LOAD_MORE);
    }

    @PostMapping("article/loadnew")
    public ResponseResult loadNew(@RequestBody ApArticleHomeDto homeDto){
        return articleService.load(homeDto,ArticleConstants.LOAD_NEW);
    }

    /**
    @PostMapping("article/save")
    public ResponseResult save(@RequestBody ApArticleDto articleDto){
        return articleService.saveArticle(articleDto);
    }


    /**
     * 用户收藏
     * @return
     */
    @PostMapping("/collection_behavior")
    public ResponseResult userCollection(@RequestBody CollectionBehaviorDto dto,  HttpServletRequest request){
        String userId = request.getHeader("userId");
        log.info("获取到用户ID：{}",userId);
        return articleService.feignToUser(dto,userId);
    }

    @PostMapping("/article/queryChanner")
    public Integer queryChanner(@RequestBody WmChannel wmChannel){
       Integer ChannelNum =articleService.queryChanner(wmChannel);
       return ChannelNum;

    }

}